package 面试题28_对称的二叉树;

/**
 * @Author ：xu_xiaofeng.
 * @Date ：Created in 11:16 2021/3/14
 * @Description：
 */
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;

    TreeNode(int x) {
        val = x;
    }
}

public class Solution {
    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;

        return isSymmetric(root, root);
    }


    boolean isSymmetric(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) return true; // 同时为null

        if(root1 == null || root2 == null) return false;// 只有一个为null的情况

        if(root1.val != root2.val) return false;

        // 若相等，且不为null，则继续判断判断
        return isSymmetric(root1.left, root2.right) && isSymmetric(root1.right, root2.left);
    }
}
